package com.neusoft.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.neusoft.bean.TabBbsTopicinfo;
import com.neusoft.service.IJieService;
import com.neusoft.util.StringDateUtil;

@Controller
public class HomeController {
	
	@Autowired
	//@Autowired要去spring容器去托管
	private IJieService iJieService;
	
	
	/**
	 * 发帖的，即，主页面的
	 * @return
	 */
	@RequestMapping("/")
	public ModelAndView index() {
		List<Map<String, Object>> lstTopic = iJieService.getAllTopics();

		for (Map<String, Object> map:lstTopic) {
			for(Map.Entry<String, Object> entry:map.entrySet()){
				if ("commentTime".equals(entry.getKey())) {
					String dateStr = StringDateUtil.getStringDate((Date) entry.getValue());
					entry.setValue(dateStr);
				}
			}
		}
		
//		System.out.println(lstTopic.size());
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("topics", lstTopic);
		modelAndView.setViewName("index");
		return modelAndView;
	}

}
